<?php

namespace App\Http\Controllers\Admin\Customer;

use App\Http\Controllers\Controller;
use App\Models\customer\ApiModel;
use Illuminate\Http\Request;

class Api extends Controller
{
    protected $bigbag_callback_status = [
        'received',
        'export_custom_clearance_start',
        'export_custom_clearance_success',
        'prebooking',
        'preadvice',
        'uplifted',
        'arrived',
        'import_custom_clearance_start',
        'import_custom_clearance_success',
        'handovered'
    ];

    /**
     * Notes:列表
     * User: xiangzi
     * Date: 2024/9/5
     * Time: 14:35
     * @return \Illuminate\Http\JsonResponse
     */
    public function list(Request $request) {

        $customer_id = $request->input('customer_id', '');


        $query = ApiModel::query();

        if($customer_id){
            $query = $query->where('customer_id', $customer_id);
        }

        $items = $query->get();

        $list = $items->map(function($item) {
            $res = [
                'id' => $item->id,
                'customer_id' => $item->customer_id,
                'api' => $item->api,
                'name' => $item->name,
                'status' => $item->api == 'CAINIAO_GLOBAL_LINEHAUL_BIGBAGSTATUS_CALLBACK' ? $this->bigbag_callback_status : [],
            ];
            return $res;
        });

        return $this->success(['list' => $list]);
    }


}
